import { prop, modelOptions } from '@typegoose/typegoose'
import { ApiProperty } from '@nestjs/swagger'
import { hashSync } from 'bcryptjs'
import { truncate } from 'fs/promises'

@modelOptions({
    schemaOptions: {
        timestamps: true
    }
})
export class User {
    @ApiProperty({ description: '用户名', example: 'user1'})
    @prop({
        unique: true
    })
    username: string

    @ApiProperty({ description: '密码', example: 'pass1'})
    @prop({
        select: false,
        get(val){
            return val
        },
        set(val){
            return val ? hashSync(val): val
        }
    })
    password: string

    @ApiProperty({ description: '描述', example: '测试用户描述'})
    @prop()
    description: string
}